package activity;

import hcs.HouseController;
import hcs.interfaces.IHouseSettings;
import hcs.model.InvalidTimeException;
import hcs.model.Room;
import hcs.model.RoomSettings;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SetRoomParametersActivity {

	public static void setRoomParameter(Room room, String name, Class<?> valueType, Object value)  {
		try {
			RoomSettings settings = room.getSettings();
			Method method = settings.getClass().getMethod("set" + name, valueType);
			method.invoke(settings, value);
		} catch (InvocationTargetException e) {
			Throwable trueException = e.getCause();
			if (trueException instanceof InvalidTimeException) {
				InvalidTimeException timeExc = (InvalidTimeException) trueException;
				timeExc.printStackTrace(); 
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public static Number getDefaultParameter(HouseController hc, String name)  {
		Method m;
		Number ret = 0;
		IHouseSettings settings = hc.getHouseSettings();
		try {
			m = settings.getClass().getMethod(name);
			ret = (Number) m.invoke(settings, (Object[]) null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}
	
}
